apiready = function(){
seajs.use(['../../V',"../../api","../../jquery","../../app","../../service"],function(V,$api,$,app,service){
	var vm = {
		el: '.container',
	  	data: {
	  		activeIndex: 0,
				activeUpIndex: 0,
	  		orderNumber: {
	  			unpay_num: '',
	  			pay_num: '',
	  			express_num: '',
	  			refund_num: '',
					comment_num: '',
					finish_num: ''
	  		},
	    	orderList: [],
				order_state: 1,
				page: 1,
				shopId: '',
				tem_order_id: '',
				refundPrice:'',
				order_return_id: '',
	  	},
	  	mounted:function() {

	  	},
	  	methods:{
				// alert(JSON.stringify(ret));
				openSearch: function(){
					this.searchName = $("#search-input").val();
					app.openWin('orderSearch',{shopId: api.pageParam.shopId, searchName: this.searchName})
				},
				//--获取订单列表（包含订单数量）
				orderListGet: function(scrolltobottom){
					// var shopId = api.pageParam.shopId; // 商店id
					var unionid = $api.getStorage("shop_unionid"); // 用户id
					var that = this;

					app.ajax(service['orderListGet'],
					{
						data: {
							values: {
								unionid: unionid,
								page: this.page,
								order_state: this.order_state
							}
						}
					},
					function (res) {
						if(res.code){
							alert("错误代码code："+res.code+"\n错误信息："+res.message)
						}else{
							if(res.data != ''){
								// console.log(that.orderList.constructor);
								that.orderNumber.unpay_num = res.data.unpay_num;
								that.orderNumber.pay_num = res.data.pay_num;
								that.orderNumber.express_num = res.data.express_num;
								that.orderNumber.refund_num = res.data.refund_num;
								that.orderNumber.comment_num = res.data.comment_num;
								that.orderNumber.finish_num = res.data.finish_num;

								console.log("获取商品列表成功!");

							}else if(res.data == ''){
									api.toast({
										msg: '该状态下没有任何订单',
										duration: 2000,
										location: 'middle'
									});
							}


						}
					});
				},

				upOrderTab: function(indes){
					var that = this;

	  			if(indes == '-1'){
	  				return;
	  			}else if(indes == 0){	//--进行中
						$(".shop_order_finish").css("display", "none");
						$(".shop_order_await").css("display", "flex");

						this.activeIndex = 0;	//点击“进行中”的时候默认选中待付款
						this.order_state = 1;	//点击“进行中”的时候默认获取待付款订单
					}else if(indes == 1){	//--已完成
						$(".shop_order_finish").css("display", "flex");
						$(".shop_order_await").css("display", "none");

						this.activeIndex = 4;	//点击“已完成”的时候默认选中待评价
						this.order_state = 4;	//点击“已完成”的时候默认获取待评价订单
					}else if(indes == 2){	//--已关闭
						//--已关闭，隐藏订单状态统计框
						$(".shop_order_finish").css("display", "none");
						$(".shop_order_await").css("display", "none");

						this.order_state = 6;	//点击“已关闭”的时候获取已关闭订单
					}else if(indes == 3){	//--已退款/退货
						//--已退款/退货，隐藏订单状态统计框
						$(".shop_order_finish").css("display", "none");
						$(".shop_order_await").css("display", "none");

						this.order_state = 8;	//点击“已关闭”的时候获取已关闭订单
					}
					this.activeUpIndex = indes;

					//--获取已关闭订单列表
					var scrolltobottom = 0;
					this.orderListGet(scrolltobottom);

					api.sendEvent({
					    name: 'upOrderTab',
					    extra: {
					        inds: indes,
					    }
					});
				},
				orderTab: function(indes){
					var that = this;

	  			if(indes == '-1'){
	  				return;
	  			}else if(indes == 0){
						this.order_state = 1;
					}else if(indes == 1){
						this.order_state = 2;
					}else if(indes == 2){
						this.order_state = 3;
					}else if(indes == 3){
						this.order_state = 7;
					}else if(indes == 4){
						this.order_state = 4;
					}else if(indes == 5){
						this.order_state = 5;
					}
					this.page = 1;
	  			this.activeIndex = indes;

	  			//--改变orderList的数据
					var scrolltobottom = 0;
					this.orderListGet(scrolltobottom);

					api.sendEvent({
					    name: 'orderTab',
					    extra: {
					        inds: indes,
					    }
					});
				},
	  	},
	  	created: function(){
				var that = this;
				this.shopId = api.pageParam.shopId;

				var scrolltobottom = 0;
				this.orderListGet(scrolltobottom);

				//--监听订单状态数据变化
				api.addEventListener({
						name: 'close_win_refresh',
				}, function(ret, err){
						that.shopId = ret.value.shopId;
						var scrolltobottom = 0;
						that.orderListGet(scrolltobottom);
				});
	  	}
	};

	var even = function() {}
	var newVue = new Vue(vm);
	even();
});
}
